package com.example.controller;


import com.example.pojo.Dept;
import com.example.pojo.Disciple;
import com.example.pojo.PageBean;
import com.example.pojo.Result;
import com.example.service.DiscipleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

/**
 * 教会员工管理Controller
 */
@Slf4j
@RestController
@RequestMapping("/disciple")
public class DiscipleController {
    @Autowired
    private DiscipleService discipleServicel;

    @PostMapping
    public Result save(@RequestBody Disciple disciple) {
        log.info("新增教徒，dis：{}", disciple);
        discipleServicel.save(disciple);
        return Result.success();
    }

    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids) {
        log.info("批量删除，ids：{}", ids);
        discipleServicel.delete(ids);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody Disciple disciple) {
        log.info("更新教徒信息：{}", disciple);
        discipleServicel.update(disciple);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        log.info("根据id查询教徒信息，id:{}", id);
        Disciple disciple = discipleServicel.getById(id);
        return Result.success(disciple);
    }

    /**
     * 条件查询数据
     * @return
     */
    @GetMapping
    public Result page(String name, Short gender,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize){
        Boolean ise=false;
        PageBean pageBean = discipleServicel.page(name, gender, begin, end, page, pageSize,ise);
        log.info("查询全部教徒数据,deptlist:{}",pageBean);
        return Result.success(pageBean);
    }

    /**
     * 条件查询数据2
     * 教会会员查询
     * @return
     */
    @GetMapping("/s")
    public Result page2(String name, Short job,Short deptId,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize){
        Boolean ise=true;
        PageBean pageBean = discipleServicel.page2(name, job,deptId, begin, end, page, pageSize,ise);
        log.info("条件查询教徒数据,deptlist:{}",pageBean);
        return Result.success(pageBean);
    }

    /**
     * 获取所有的职位信息
     * @return
     */
    @GetMapping("/jobList")
    public Result jobList(){
        //调用service 查询部门数据
        List<Disciple> jobList=discipleServicel.jobList();
        log.info("查询全部职位信息,jobList:{}",jobList.get(0));
        return Result.success(jobList);
    }


}
